package helper
{
	import control.MainController;
	
	import flash.events.Event;
	
	import model.MainModel;
	
	import org.servebox.foundry.model.ModelLocator;
	import org.servebox.foundry.observation.IObservable;
	import org.servebox.foundry.observation.Notification;
	import org.servebox.foundry.view.ViewHelper;
	
	import value.ContactListTO;
	
	import view.MainView;

	public class MainViewHelper extends ViewHelper
	{
		public function MainViewHelper()
		{
			super();
		}
		
		override public function registerToModels() : void
		{
			ModelLocator.getInstance().getModel( MainController.MAIN_MODEL_ID ).registerObserver( this );
		}
		
		public function initDatas():void
		{
			MainController.getInstance().getAllContact();
			/* getMainModel().initialize(); */
		}
		
		[Bindable("contactListChanged")]
		public function get contactList() : ContactListTO
		{
			return getMainModel().contactList;
		}
		
		// Notifications
		
		public function contactListChangedNotification_Fired( o : IObservable, n :Notification ) : void
		{
			//trace("contactListChangedNotification received.");
			dispatchEvent( new Event("contactListChanged") );
		}
		
		// Shortcuts
		
		/**
		* return a reference to MainModel
		*/
		
		protected function getMainModel() : MainModel
		{
			return MainModel ( ModelLocator.getInstance().getModel( MainController.MAIN_MODEL_ID ));
		}
		
		private function getCurrentView( ) : MainView
		{
			return MainView( getView() );
		}
	}
}